package model;

import communication.Alarm;
import communication.GasAlarm;
import communication.RadiationAlarm;

/**
 * Monitor B class
 * @author Adrien Ledeul
 * @version 0.1
 */
public class MonitorB extends Monitor
{
	/**
	 * Constructors
	 * 
	 */
	public MonitorB(Set set) 
	{
		super(set);
	}
	
	/**
	 * Alarm receiver
	 * @param alarm Alarm
	 */
	@Override
	public void receiveAlarm(Alarm alarm) 
	{
		super.receiveAlarm(alarm);
		
		if (alarm instanceof GasAlarm) 
		{
			GasAlarm gasAlarm = (GasAlarm) alarm;
			
			String longA = "Gas alarm! \nDate:"+ gasAlarm.getDate() + "\nPlace:" + gasAlarm.getPlace() + "\nPriority:" + gasAlarm.getPriority() + "\nType:" + gasAlarm.getType();
			String shortA = "Gas alarm! date:"+ gasAlarm.getDate();
			log.add(new AlarmLog(shortA, longA, alarm));
			System.out.println(longA);
		}
		
		else if (alarm instanceof RadiationAlarm) 
		{
			RadiationAlarm radiationAlarm = (RadiationAlarm) alarm;
			
			String longA = "Radiation alarm! \nDate:"+ radiationAlarm.getDate() + "\nPlace:" + radiationAlarm.getPlace() + "\nPriority:" + radiationAlarm.getPriority() + " \nLevel:" + radiationAlarm.getLevel();
			String shortA = "Radiation alarm! date:"+ radiationAlarm.getDate();
			log.add(new AlarmLog(shortA, longA, alarm));
			System.out.println(longA);
		}
		set.serialize();
	}
}
